package com.xqgl.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xqgl.bean.Pet;
import com.xqgl.service.PetDaoImp;

/**
 * Servlet implementation class addPetServlet
 */
@WebServlet("/addPetServlet")
public class addPetServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addPetServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;Charset=utf-8");
		String petpicture = request.getParameter("petpicture");
		String username = request.getParameter("username");
		String petname = request.getParameter("petname");
		String petcolour = request.getParameter("petcolour");
		String petremark = request.getParameter("petremark");
		String sytime = request.getParameter("sytime");
		String petctime = request.getParameter("petctime");
		Pet pet = new Pet();
		pet.setPetpicture(petpicture);
		pet.setUsername(username);
		pet.setPetname(petname);
		pet.setPetcolour(petcolour);
		pet.setPetremark(petremark);
		pet.setSytime(sytime);
		pet.setPetctime(petctime);
		PetDaoImp imp = new PetDaoImp();
		try {
			imp.add(pet);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.sendRedirect("petlist.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
